package com.zougen202301180355.restaurant.service.impl;

import com.zougen202301180355.restaurant.mapper.OrdersMapper;
import com.zougen202301180355.restaurant.pojo.Order;
import com.zougen202301180355.restaurant.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 邹根
 * 订单服务实现类
 */
@Service
@Transactional
public class OrdersServiceImpl implements OrdersService {

    @Autowired
    private OrdersMapper ordersMapper;

    @Override
    public void addOrder(Order order) {
        ordersMapper.insert(order);
    }

    @Override
    public void deleteOrder(Integer id) {
        ordersMapper.delete(id);
    }

    @Override
    public void updateOrder(Order order) {
        ordersMapper.update(order);
    }

    @Override
    public Order getOrderById(Integer id) {
        return ordersMapper.selectById(id);
    }

    @Override
    public List<Order> getAllOrders() {
        System.out.println("===== OrdersService.getAllOrders 调用 =====");
        List<Order> orders = ordersMapper.selectAll();
        System.out.println("Mapper 返回的订单数量: " + (orders == null ? "null" : orders.size()));
        return orders;
    }

    @Override
    public Order getOrderWithDetails(Integer id) {
        return ordersMapper.selectWithCustomerAndOrderDetails(id);
    }
}
